package com.openbravo.data.loader;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DataWriteUtils
{
  private static DateFormat tsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

  public static String getSQLValue(Object paramObject)
  {
    if (paramObject == null)
      return "NULL";
    if ((paramObject instanceof Double))
      return getSQLValue((Double)paramObject);
    if ((paramObject instanceof Integer))
      return getSQLValue((Integer)paramObject);
    if ((paramObject instanceof Boolean))
      return getSQLValue((Boolean)paramObject);
    if ((paramObject instanceof String))
      return getSQLValue((String)paramObject);
    if ((paramObject instanceof Date))
      return getSQLValue((Date)paramObject);
    return getSQLValue(paramObject.toString());
  }

  public static String getSQLValue(Integer paramInteger)
  {
    if (paramInteger == null)
      return "NULL";
    return paramInteger.toString();
  }

  public static String getSQLValue(Double paramDouble)
  {
    if (paramDouble == null)
      return "NULL";
    return paramDouble.toString();
  }

  public static String getSQLValue(Boolean paramBoolean)
  {
    if (paramBoolean == null)
      return "NULL";
    return paramBoolean.booleanValue() ? "TRUE" : "FALSE";
  }

  public static String getSQLValue(String paramString)
  {
    if (paramString == null)
      return "NULL";
    return '\'' + getEscaped(paramString) + '\'';
  }

  public static String getSQLValue(Date paramDate)
  {
    if (paramDate == null)
      return "NULL";
    return "{ts '" + tsf.format(paramDate) + "'}";
  }

  public static String getEscaped(String paramString)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < paramString.length(); i++)
      switch (paramString.charAt(i))
      {
      case '\\':
        localStringBuffer.append("\\\\");
        break;
      case '\'':
        localStringBuffer.append("\\'");
        break;
      case '\n':
        localStringBuffer.append("\\n");
        break;
      case '\r':
        localStringBuffer.append("\\r");
        break;
      default:
        localStringBuffer.append(paramString.charAt(i));
      }
    return localStringBuffer.toString();
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.loader.DataWriteUtils
 * JD-Core Version:    0.6.0
 */